package gdt.mvc;

import java.util.List;


import gdt.entity.Category;
import gdt.entity.Client;
import gdt.entity.Group;
import gdt.entity.Member;
import gdt.entity.Project;
import gdt.entity.Task;
import gdt.entity.embeddable.Address;
import gdt.entity.embeddable.Contact;
import gdt.service.GroupService;
import gdt.service.MemberService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;


public class Populator extends AbstractController {	
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
		Group group = new Group();
		group.setName("Primero");
		
		Client c1 = new Client();
		c1.setName("Raro");
		c1.getContact().setName("contactoderaro");
		group.addClient(c1);
		
		
		Member member = new Member();
		Contact contact = new Contact();
		contact.setName("Primerix Member");
		member.setContact(contact);
		member.setUsername("user");
		member.setPassword("");
		member.addAuthority("ROLE_USER");
		member.addAuthority("ROLE_ADMIN");
		group.addMember(member);
		
		
		
		Project project = new Project();
		project.setName("Rule the world");
		project.setRetired(false);
		project.setDescription("Muahuahuahuahua");
		group.addProject(project);
		project.addMember(member);
		
		Category cat = new Category();
		cat.setName("Get monkeys");
		cat.setDescription("Get a lot of wild monkeys");
		project.addCategory(cat);
		
		Category cat2 = new Category();
		cat2.setName("Invent the mortal bean");
		cat2.setDescription("Make scientists to invent the super mortal bean");
		project.addCategory(cat2);
		
		Category subcat21 = new Category();
		subcat21.setName("Recruit scientists");
		subcat21.setDescription("Get some scientists");
		cat2.addCategory(subcat21);
		
		Category subcat = new Category();
		subcat.setName("Get equipment");
		subcat.setDescription("Get some kickass weapons");
		cat.addCategory(subcat);
		
		Task task = new Task();
		task.setComment("It was hard");
		cat.addTask(task);
		member.addTask(task);
		
		Task task2 = new Task();
		task2.setComment("It was hell");
		cat.addTask(task2);
		member.addTask(task2);

		
		Address ad = new Address();
		ad.setStreet("Asd");
		ad.setCity("Centropolis");
		group.setAddress(ad);
		groupService.save(group);
		
		
		List<Group> groups = groupService.getGroups();
		
		
		return new ModelAndView("groups","groupList",groups);
	}

	private GroupService groupService;

	public void setGroupService(GroupService groupService) {
		this.groupService = groupService;
	}
	
	private MemberService memberService;


	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}
	
	
	
	

	
	

}
